import get from '@dfeidao/atom-web/local/get';
import remove from '@dfeidao/atom-web/local/remove';
import set from '@dfeidao/atom-web/local/set';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import set_node_cls from '@dfeidao/atom-web/ui/set-node-cls';
import set_nodes_cls from '@dfeidao/atom-web/ui/set-nodes-cls';
import { IFeidaoAiBrowserComponent } from '@dfeidao/web/interfaces';
import hide_loading from '../../atom/hide-loading';
import show_loading from '../../atom/show-loading';
import P02 from './P02';
import P03 from './P03';
import P06 from './P06';

export default async function a005(fd: IFeidaoAiBrowserComponent, args: { currentTarget: HTMLInputElement }) {
	const node = args.currentTarget as HTMLDivElement;
	const nodes = Array.from(fd.data.node.querySelectorAll('[dalist2]')) as HTMLElement[];
	const productid = get(fd, 'productid');
	set_nodes_cls(nodes, 'bg-c', false);
	set_node_cls(node, 'bg-c', true);
	const id = node.getAttribute('_id');
	const pk_val = node.getAttribute('pk_val');
	// debugger;
	set(fd, 'role_allot_id', id);
	set(fd, 'pk_val', pk_val);
	set(fd, 'ff', id);
	remove(fd, 'allot_group');
	remove(fd, 'shezhi');
	show_loading();
	const data = await nodejs<{ length: number }>('roler/service/allot_conditions_group_find', { productid, role_allot_id: id });
	hide_loading();
	if (data.length === 0) {
		render(fd, '', P02, 'P02', 'inner');
	} else {
		render(fd, data, P02, 'P02', 'inner');
	}
	render(fd, '', P06, 'P06', 'inner');
	render(fd, '', P03, 'P03', 'inner');
}
